package com.xzqwjw.taskmanager.activity;

import com.xzqwjw.taskmanager.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageButton;

public class ActivityMain extends Activity implements OnClickListener {

  private String strDBFile = "";

  private ImageButton imgbtnAll;
  private ImageButton imgbtnUnit;
  private ImageButton imgbtnCondition;

  private ImageButton imgbtnFavorite;
  private ImageButton imgbtnSetting;
  private ImageButton imgbtnQuit;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);

    Intent objIT = getIntent();
    strDBFile = objIT.getStringExtra("DBFilePath");

    initView();
    initClickEvent();
  }

  private void initView() {
    imgbtnAll = (ImageButton) findViewById(R.id.imgbtn_all);
    imgbtnUnit = (ImageButton) findViewById(R.id.imgbtn_unit);
    imgbtnCondition = (ImageButton) findViewById(R.id.imgbtn_condition);

    imgbtnFavorite = (ImageButton) findViewById(R.id.imgbtn_favorite);
    imgbtnSetting = (ImageButton) findViewById(R.id.imgbtn_setting);
    imgbtnQuit = (ImageButton) findViewById(R.id.imgbtn_quit);
  }

  private void initClickEvent() {
    imgbtnAll.setOnClickListener(this);
    imgbtnUnit.setOnClickListener(this);
    imgbtnCondition.setOnClickListener(this);

    imgbtnFavorite.setOnClickListener(this);
    imgbtnSetting.setOnClickListener(this);
    imgbtnQuit.setOnClickListener(this);
  }

  @Override
  public void onClick(View v) {
    Intent objIT;
    int id = v.getId();
    if (id == R.id.imgbtn_all) {
      objIT = new Intent(ActivityMain.this, ActivityAll.class);
      objIT.putExtra("DBFilePath", strDBFile);
      startActivity(objIT);
    } else if (id == R.id.imgbtn_unit) {
      objIT = new Intent(ActivityMain.this, ActivityUnit.class);
      objIT.putExtra("DBFilePath", strDBFile);
      startActivity(objIT);
    } else if (id == R.id.imgbtn_condition) {
      objIT = new Intent(ActivityMain.this, ActivityCondition.class);
      objIT.putExtra("DBFilePath", strDBFile);
      startActivity(objIT);
    } else if (id == R.id.imgbtn_favorite) {
      objIT = new Intent(ActivityMain.this, ActivityFavorite.class);
      objIT.putExtra("DBFilePath", strDBFile);
      startActivity(objIT);
    } else if (id == R.id.imgbtn_setting) {
      objIT = new Intent(ActivityMain.this, ActivitySetting.class);
      objIT.putExtra("DBFilePath", strDBFile);
      startActivity(objIT);
    } else if (id == R.id.imgbtn_quit) {
      android.os.Process.killProcess(android.os.Process.myPid());
    } else {
    }
  }

}
